package com.googlecode.jch.plugin.runconfiguration;

import com.googlecode.jch.plugin.Icons;
import com.intellij.execution.RunConfigurationExtension;
import com.intellij.execution.configuration.ConfigurationFactoryEx;
import com.intellij.execution.configurations.*;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * @author Iskander Akishev
 */
public class JCHRunConfigurationType implements ConfigurationType {
	private final ConfigurationFactory myFactory;
	private static final Icon ICON = Icons.SOLUTION;

	public JCHRunConfigurationType() {
		myFactory = new ConfigurationFactoryEx(this) {
			public RunConfiguration createTemplateConfiguration(Project project) {
				return new JCHRunConfiguration("", project, JCHRunConfigurationType.this);
			}

			@Override
			public Icon getIcon(@NotNull final RunConfiguration configuration) {
				return RunConfigurationExtension.getIcon((JCHRunConfiguration) configuration, getIcon());
			}

			@Override
			public void onNewConfigurationCreated(@NotNull RunConfiguration configuration) {
				((ModuleBasedConfiguration)configuration).onNewConfigurationCreated();
			}
		};
	}

	public String getDisplayName() {
		return "Solution";
	}

	public String getConfigurationTypeDescription() {
		return "Solution configuration";
	}

	public Icon getIcon() {
		return ICON;
	}

	public ConfigurationFactory[] getConfigurationFactories() {
		return new ConfigurationFactory[]{myFactory};
	}

	@NotNull
	@NonNls
	public String getId() {
		return "JCHSolution";
	}

	@Nullable
	public static JCHRunConfigurationType getInstance() {
		return ConfigurationTypeUtil.findConfigurationType(JCHRunConfigurationType.class);
	}
}
